package com.sth.shishan;

import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.text.ParseException;

/**
 * @Author: sitianhong
 * @Description: 秒杀活动下的公平队列抢购机制 list
 * @Since: create in 2021/6/13 0013 17:58
 */
public class RedisDemo5 {
    Jedis jedis = new Jedis("127.0.0.1", 6378);

    @Test
    public void demo1() {
        for (int i = 0; i < 10; i++) {
            enqueueSeckillRequest("第 " + (i + 1) + " 个秒杀请求");
        }
        while (true) {
            String s = dequeueSeckillRequest();
            if (null != s) {
                System.out.println(s);
            }

        }

    }

    // 入队
    public void enqueueSeckillRequest(String secKillRequest) {
        jedis.lpush("sec_kill_request_queue", secKillRequest);
    }

    // 出队
    public String dequeueSeckillRequest() {
        return jedis.rpop("sec_kill_request_queue");
    }


}
